----------------------------------------------------------------------------------------------------------------------------------
--[[

    

]]--
----------------------------------------------------------------------------------------------------------------------------------
local loramia_com_tent = Class(function(self, inst)
    self.inst = inst

    ---------------------------------------------------------------------
    --- 键盘监听        
        self.keyboard_listeners = {}        
        self.inst:ListenForEvent("acive_key_board_event_listener",function(inst,_table)
            local userid = _table and _table.userid
            -- print("replica acive_key_board_event_listener",userid)
            if TheInput and ThePlayer and ThePlayer.userid == userid then
                self:OnAciveKeyBoardEventForPlayer(ThePlayer)
            end
        end)
        self.inst:ListenForEvent("deactive_key_board_event_listener",function(inst,_table)
            local userid = _table and _table.userid
            -- print("replica deactive_key_board_event_listener",userid)
            if TheInput and ThePlayer and ThePlayer.userid == userid then
                self:DeactiveKeyBoardEventForPlayer(ThePlayer)
            end
        end)
        self.inst:ListenForEvent("onremove",function()
            for k, v in pairs(self.keyboard_listeners) do
                v:Remove()
            end
        end)

        self.custom_key_board_event = false
        self.__custom_key_board_event = net_bool(inst.GUID,"loramia_com_tent","custom_key_board_event")
        self.inst:ListenForEvent("custom_key_board_event",function()
            self.custom_key_board_event = self.__custom_key_board_event:value()
        end)
    ---------------------------------------------------------------------
end)
------------------------------------------------------------------------------------------------------------------------------
---
    function loramia_com_tent:SetTestFn(fn)
        self.test_fn = fn
    end
    function loramia_com_tent:Test(doer)
        if self.test_fn then
            return self.test_fn(self.inst,doer)
        end
        return false
    end
------------------------------------------------------------------------------------------------------------------------------
--- 键盘监听
    function loramia_com_tent:SetCustomKeyboardEvent(flag)
        self.custom_key_board_event = flag
        if TheWorld.ismastersim then
            self.__custom_key_board_event:set(flag)
        end
    end
    function loramia_com_tent:IsUsingCutomKeyboardEvent()
        return self.custom_key_board_event
    end
    function loramia_com_tent:SetCustomOnActiveKeyBoardEvent(fn)
        self.custom_on_active_key_board_event = fn
    end
    function loramia_com_tent:SetCustomOnDeactiveKeyBoardEvent(fn)
        self.custom_on_deactive_key_board_event = fn
    end
    function loramia_com_tent:OnAciveKeyBoardEventForPlayer(player)
        if TheCamera then
            TheCamera:SetTarget(self.inst)
        end
        if self:IsUsingCutomKeyboardEvent() then
            if self.custom_on_active_key_board_event then
                self.custom_on_active_key_board_event(self.inst,player)
            end
            return
        end
        self:DeactiveKeyBoardEventForPlayer(player)
        self.keyboard_listeners[player] = TheInput:AddKeyHandler(function(key,down)
            -- print("tent +++ key",key,down)
            if down then
                self:PlayerCommandWakeUp(player)
                -- self:DeactiveKeyBoardEventForPlayer(player)
            end
        end)
    end
    function loramia_com_tent:DeactiveKeyBoardEventForPlayer(player)
        if TheCamera then
            TheCamera:SetTarget(player)
        end
        if self:IsUsingCutomKeyboardEvent() then
            if self.custom_on_deactive_key_board_event then
                self.custom_on_deactive_key_board_event(self.inst,player)
            end
            return
        end
        if self.keyboard_listeners[player] then
            self.keyboard_listeners[player]:Remove()
            self.keyboard_listeners[player] = nil
        end
    end
------------------------------------------------------------------------------------------------------------------------------
---
    function loramia_com_tent:PlayerCommandWakeUp(player)
        local rpc = player.replica.loramia_com_rpc_event
        if rpc then
            rpc:PushEvent("player_command_wake_up",{
                userid = player.userid
            },self.inst)
        end
    end
------------------------------------------------------------------------------------------------------------------------------
return loramia_com_tent







